package com.lgc.javathread.threadLocalTest.test3;

import java.util.concurrent.TimeUnit;

public class NumUtil {

//    public static int addNum = 0; //线程不安全，因为是共享的
private static ThreadLocal<Integer> threadLocals = new ThreadLocal<>();

    public static int add10(int num) {
//        addNum = num;
        threadLocals.set(num);

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

//        return addNum + 10;
        return threadLocals.get() + 10;
    }
}
